﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace FYPHP
{
    public partial class SeachStaff2 : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);
        int u_id;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                String IC = Session["IC"].ToString();
                String Name = Session["Name"].ToString();

                SqlCommand cmdUser;
                SqlDataReader dtrUser;
                conn.Open();

                cmdUser = new SqlCommand("Select * From Users where u_ic=@IC OR username=@Name ", conn);
                cmdUser.Parameters.AddWithValue("@IC", IC);
                cmdUser.Parameters.AddWithValue("@Name", Name);

                dtrUser = cmdUser.ExecuteReader();


                UserList.DataSource = dtrUser;
                UserList.DataBind();


                dtrUser.Close();
                conn.Close();
            }
            catch (SqlException ex)
            {

            }
        }

        protected void rpt_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
        {

            if (e.CommandName == "ViewMember")
            {
                MultiView1.ActiveViewIndex = 0;
                u_id = Convert.ToInt32(e.CommandArgument.ToString());
                try
                {
                    SqlCommand cmdUser;
                    SqlDataReader dtrUser;
                    conn.Open();

                    cmdUser = new SqlCommand("Select * From Users where u_id = @Id", conn);
                    cmdUser.Parameters.AddWithValue("@Id", u_id);
                    dtrUser = cmdUser.ExecuteReader();
                    dtrUser.Read();

                    String userName = dtrUser["username"].ToString();
                    String gender = dtrUser["u_gender"].ToString();
                    String age = dtrUser["u_age"].ToString();
                    String address = dtrUser["u_address"].ToString();
                    String email = dtrUser["u_email"].ToString();
                    String rewardpoint = dtrUser["u_points"].ToString();

                    lblPID.Text = u_id.ToString();
                    lblName.Text = userName;
                    lblGender.Text = gender;
                    lblAge.Text = age;
                    lblAddress.Text = address;
                    lblEmail.Text = email;
                    lblRewardPoints.Text = rewardpoint;

                    dtrUser.Close();
                    conn.Close();
                }
                catch (SqlException ex)
                {

                }


            }

        }

        public String return_userpicture()
        {

            SqlCommand cmdUser;
            SqlDataReader dtrUser;
            conn.Open();

            cmdUser = new SqlCommand("Select * From Users where u_id =@Id", conn);

            cmdUser.Parameters.AddWithValue("@Id", u_id);
            dtrUser = cmdUser.ExecuteReader();

            dtrUser.Read();
            String userPicture = dtrUser["u_picture"].ToString();

            dtrUser.Close();
            conn.Close();


            return userPicture;

        }

    }
}